package com.cyanite.playlv2api.parsers.json;

import com.cyanite.playlv2api.types.Tip;

import org.json.JSONException;
import org.json.JSONObject;

public class TipParser extends AbstractParser<Tip> {

    @Override
    public Tip parse(JSONObject json) throws JSONException {

        Tip obj = new Tip();
        if (json.has("date")) {
            obj.setPostDate(json.getString("date"));
        }
        if (json.has("distance")) {
            obj.setDistance(json.getString("distance"));
        }
        if (json.has("cid")) {
            obj.setId(String.valueOf(json.getInt("cid")));
        }
        if (json.has("shout")) {
            obj.setShout(json.getString("shout"));
        }
        if (json.has("uid")) {
            obj.setUserId(String.valueOf(json.getString("uid")));
        }
        if (json.has("nick")) {
            obj.setUserName(json.getString("nick"));
        }
        if (json.has("tid")) {
            obj.setTripId(String.valueOf(json.getInt("tid")));
        }
        if (json.has("tname")) {
            obj.setTripName(json.getString("tname"));
        }
        if (json.has("avatar")) {
            obj.setUserPhoto(json.getString("avatar"));
        }
        if (json.has("venue")) {
            obj.setVenue(new VenueParser().parse(json.getJSONObject("venue")));
        }
        return obj;
    }
}
